package com.hmc;
import java.io.BufferedReader;
import java.io.FileReader;  
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class ReadTxtFile {



    public static void main(String[] args) {

        SQLHelper sqlHelper = new SQLHelper();
        List<String> list = new ArrayList<String>();
        String filePath = "C:\\Users\\23046\\Desktop\\文件\\bishe\\数据库\\查表.txt";
        BufferedReader reader = null;  
        try {  
            reader = new BufferedReader(new FileReader(filePath));  
            String line;  
            while ((line = reader.readLine()) != null) {  
//                System.out.println(line);
                list.add(line);
            }  
        } catch (IOException e) {  
            e.printStackTrace();  
        } finally {  
            try {  
                if (reader != null) {  
                    reader.close();  
                }  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }

        List<String> list_student = new ArrayList<String>();
        for ( String s : list ) {
            String s1 = "(SELECT COUNT(*) FROM "+s+") as "+s+",";
            list_student.add(s1);
            System.out.println(s1);
        }


        String sql = "SELECT COUNT(*) FROM ";
        for ( String s : list ) {
//            String sql = "SELECT COUNT(*) FROM "+s+";";
            sql = sql + s + ",";
        }
//        System.out.println(sql);

//
//        for (int i = 0; i < list.size(); i++) {
//            Connection conn = null;
//            Statement stmt = null;
//            ResultSet rs = null;
//            try {
//                conn = sqlHelper.getOracleConnection();
//
//                // 执行查询并获取结果
//                stmt = conn.createStatement();
//                String sql = "SELECT COUNT(*) FROM "+list.get(i);
//                System.out.println(sql);
//                rs = stmt.executeQuery(sql);
//
//                // 过程结果
//                if (rs.next()) {
//                    int rowCount = rs.getInt(1);
////                    System.out.println(list.get(i)+"表中有"+rowCount+"条数据");
//                }
//            } catch (SQLException e) {
//                e.printStackTrace();
//            } catch (ClassNotFoundException e) {
//                e.printStackTrace();
//            } finally {
//                // Close resources
//                try {
//                    if (rs != null) rs.close();
//                    if (stmt != null) stmt.close();
//                    if (conn != null) conn.close();
//                } catch (SQLException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
    }  
}